package toolbar;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Graphics;

import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JToolBar;

import patternobserver.Observateur;


public class VueToolBar extends JToolBar implements Observateur{
	private ControleurToolBar cToolBar;
	private OutilSelection os;
	
	public VueToolBar(ControleurToolBar ct){
		this.cToolBar=ct;
		this.setFloatable(false);
        this.setPreferredSize(new Dimension(150,100));
        this.setLayout(new FlowLayout());
        this.setBackground(new Color((int) 0xc8ddf2));
        BoutonOutils bouton2 = new BoutonOutils("Point", cToolBar, "/images/point.png");
        BoutonOutils bouton3 = new BoutonOutils("Segment", cToolBar, "/images/segment.png");
        BoutonOutils bouton4 = new BoutonOutils("Polygone", cToolBar, "/images/poly.png");
        BoutonOutils bouton5 = new BoutonOutils("Pinceau", cToolBar, "/images/pinceau.png");
        BoutonOutils bouton6 = new BoutonOutils("Cercle",cToolBar, "/images/cercle.png");
        BoutonOutils bouton7 = new BoutonOutils("Rectangle",cToolBar, "/images/rectangle.png");
        BoutonOutils bouton8 = new BoutonOutils("Selection",cToolBar, "/images/selection.png");
        BoutonOutils bouton9 = new BoutonOutils("Deplacement",cToolBar, "/images/dep.png");
        bouton2.setBorder(BorderFactory.createRaisedBevelBorder());
        bouton3.setBorder(BorderFactory.createRaisedBevelBorder());
        bouton4.setBorder(BorderFactory.createRaisedBevelBorder());
        bouton5.setBorder(BorderFactory.createRaisedBevelBorder());
        bouton6.setBorder(BorderFactory.createRaisedBevelBorder());
        bouton7.setBorder(BorderFactory.createRaisedBevelBorder());
        bouton8.setBorder(BorderFactory.createRaisedBevelBorder());
        bouton9.setBorder(BorderFactory.createRaisedBevelBorder());
        this.add(bouton2);
        this.add(bouton3);
        this.add(bouton4);
        this.add(bouton5);
        this.add(bouton6);
        this.add(bouton7);
        this.add(bouton8);
        this.add(bouton9);
        
        this.os = new OutilSelection(this.cToolBar);
        this.add(os); 
	}

	@Override
	public void update() {
		this.os.repaint();
	}
}

class OutilSelection extends JLabel{
	
	private ControleurToolBar cToolBar;
	
	public OutilSelection(ControleurToolBar ct){
	super("Outil actuel : " +ct.getmGeneral().getChoixOutils());
	this.cToolBar = ct;
	}
	
	public void paintComponent(Graphics g) {
	super.paintComponent(g);
	this.setText("Outil actuel : "+this.cToolBar.getmGeneral().getChoixOutils());
	}
}

class BoutonOutils extends JButton{
	
	ControleurToolBar controleur;
	
	public BoutonOutils (String s, ControleurToolBar cToolBar, String iconstring){
		super(s);
		Icon datIcon = new ImageIcon(getClass() .getResource(iconstring)); 
		this.setIcon(datIcon);
		this.controleur=cToolBar;
		this.addActionListener(controleur);
		this.setHorizontalAlignment(LEFT);
		this.setPreferredSize(new Dimension(130,30));
	}
}
